package com.gem.day15.生产者消费者模式;

/**包子铺线程-- 生产者*/
public class BaoZiPu extends Thread {

	private BaoZi baoZi;

	public BaoZiPu(String name, BaoZi baoZi) {
		super(name);
		this.baoZi = baoZi;
	}

	@Override
	public void run() {
		int count = 0;
		//造包子
		while (true) {
			synchronized (baoZi) {
				//有包子
				if (baoZi.flag == true) {
					//等待
					try {
						baoZi.wait();
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
				//没有包子,则造包子
				System.out.println("包子铺开始做包子...");
				if (count % 2 == 0) {
					baoZi.pier = "冰皮";
					baoZi.xianer = "五仁";
				} else {
					baoZi.pier = "薄皮";
					baoZi.xianer = "牛肉";
				}
				count++;
				//包子有了
				baoZi.flag = true;
				System.out.println("包子造好了: " + baoZi.pier + baoZi.xianer);
				System.out.println("吃货来吃吧...");
				//唤醒等待的吃货线程
				baoZi.notify();
			}
		}
	}
}
